# -*- coding: utf-8 -*-
import os

def read_file(dir_path, filename, ext):
    file_path = dir_path + "\\" + filename + ext
    if not os.path.exists(file_path):
        return

    with open(file_path, 'r', encoding='utf-8') as f:
        return f.read()

def write_file(content, dir_path, filename, ext):
    file_path = dir_path + "/" + filename + ext
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(content)
        # print("Write " + filename + ".json success")

# 清空指定文件夹下的文件
def clear_all_files(folder_path):
    file_list = os.listdir(folder_path)
    for file_name in file_list:
        file_path = os.path.join(folder_path, file_name)
        if os.path.isfile(file_path):
            os.remove(file_path)

def check_dir(dir_path):
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
